<template>
    <div>
        <head-nav></head-nav>
        <!-- 占位 -->
        <div class="zanwei-top"></div>
        <!--
        <div class="insetbox2">
          <div class="rapdetail">
            <div class="ph">
              <img :src="itemObj.TP[0]" />
            </div>
            <div class="name">
              <div class="inbox">{{itemObj.SPMC}}</div>
            </div>
            <div class="msph">
              <img :src="itemObj.TP[0]"/>
              <div class="contentA" v-html="itemObj.MS"></div>
            </div>
            <div class="btn" @click="exchangeFn(itemObj.XJ, itemObj.ID)">立即抢购</div>
          </div>
        </div> -->
        <!--底部占位-->

		<!-- new-weigang start -->
        <div class="rapcontant">
            <div class="topimg">
                <!-- <img :src="itemObj.TP[0]" > -->
                <mt-swipe :auto="4000">
                    <mt-swipe-item v-for="(item,index) in itemObj.XQT" :key="index"><img :src="item"></mt-swipe-item>
                </mt-swipe>

            </div>
            <div class="title">
                {{itemObj.SPMC}}
            </div>
            <div class="detailsm">
                <div class="jg" v-if="itemObj.XJ!=0 && itemObj.JF==0" :style="textColor">
                    ￥{{itemObj.XJ}}<span v-if="(itemObj.XJ!=itemObj.JE)"> 原价 {{itemObj.JE }}</span>
                </div>
                <div class="jg" v-else-if="itemObj.XJ==0 && itemObj.JF!=0" :style="textColor">
                    {{itemObj.JF}}积分
                </div>
                <div class="jg" v-else-if="itemObj.XJ!=0 && itemObj.JF!=0" :style="textColor">
                    ￥{{itemObj.XJ}}+{{itemObj.JF}}积分<span v-if="(itemObj.XJ!=itemObj.JE)"> 原价 {{itemObj.JE }}</span>
                </div>
                <div class="jf" :style="textColor">
                    剩余<span>{{itemObj.KC}}</span>
                </div>
            </div>
            <div class="zsjf" v-if="itemObj.ZSJF!=0" :style="textColor">
                赠送<span>{{itemObj.ZSJF}}</span>积分
            </div>
            <!-- <div class="spms">
              {{itemObj}}
            </div> -->
            <!--<div class="spjssm" v-html="itemObj.MS">

            </div>-->

            <mt-navbar v-model="selected">
                <mt-tab-item id="1">商品详情</mt-tab-item>
                <mt-tab-item id="2">兑换须知</mt-tab-item>
            </mt-navbar>
            <div class="xqxz">
                <!-- tab-container -->
                <mt-tab-container v-model="selected">
                    <mt-tab-container-item id="1">
                        <div class="spdetail contentA" v-html="itemObj.MS"></div>
                    </mt-tab-container-item>
                    <mt-tab-container-item id="2">
                        <!-- {{itemObj.DHGZ}} -->
                        <div class="contentA" v-html="itemObj.DHGZ"></div>
                    </mt-tab-container-item>
                </mt-tab-container>
            </div>
        </div>
        <div class="footbuy" @click="exchangeFn(itemObj.XJ, itemObj.ID)" :style="backgroundColor">
            立即抢购
        </div>
        
        <div class="zanwei-bottom"></div>
    </div>
</template>

<script>
    import {MessageBox, Swipe, SwipeItem, Toast} from 'mint-ui';
    import api from '@/api/api';

    export default {
        data() {
            return {
                itemObj: {},
                selected: '1'
            }
        },
        methods: {
            exchangeFn(xj, lpid) {
                let page = this;
                // 检查过期
                let userinfo = JSON.parse(sessionStorage.getItem('userinfo'));
				api.scoreToGiftDetail(page,userinfo.vipcode, lpid, cb);
		        function cb(re) {
		          if (re.code !== 0) {
                    Toast({
                        message: re.msg,
                        duration: 2000
                    });
                    setTimeout(function () {
                    	page.$router.go(-1);
                    },2000);
		          } else {
		          	let userinfo = JSON.parse(sessionStorage.getItem('userinfo'));
	                if (userinfo != null && userinfo.vipcode) {
	                    // if (true) {
	                    MessageBox.confirm('确定支付吗?', '温馨提示').then(action => {
	                        if (action === 'confirm') {
	                            if (xj > 0) {
	                                page.$router.push({
	                                    path: '/rappay/',
	                                    query: {
	                                        lpid: lpid
	                                    }
	                                })
	                            } else {
	                                let userinfo = JSON.parse(sessionStorage.getItem('userinfo'));
	                                api.scoreCreateOrder(page, userinfo.vipcode, lpid, cb)
	
	                                function cb(res) {
	                                    console.log('生订单')
	                                    console.log(res)
	                                    if (res.code == 0) {
	                                        let insertObj = {
	                                            pdid: res.data
	                                            // rowobj: this.rowobj
	                                        }
	                                        page.$router.push({
	                                            path: '/scorecreate',
	                                            query: {
	                                                create: insertObj
	                                            }
	                                        })
	                                    } else {
	                                        Toast({
	                                            message: res.msg,
	                                            duration: 3000
	                                        });
	                                    }
	
	                                }
	                            }
	                        }
	                    });
	                } else {
	                    Toast({
	                        message: '您还不是会员，快去注册吧！',
	                        duration: 2000
	                    });
	                    setTimeout(function () {
	//                      page.$router.push('/register')
	                        page.$router.push({path: '/register', query: {type: 'rapdetail'}});
	                    }, 2000)
	                }
		          }
		        }
                
            },
            /**
             * @param ID 礼品ID
             */
            getGiftDetailFn(id) {
                let page = this
                let userinfo = JSON.parse(sessionStorage.getItem('userinfo'));
                api.scoreToGiftDetail(page,userinfo.vipcode, id, cb)

                function cb(res) {
                    if (res.code == 0) {
                        let data = JSON.parse(res.data)
                        console.log(data)
                        let TP = data.TP.map(x => {
                            return page.host.filehost + x
                        })
                        data.TP = TP
                        let XQT = data.XQT.map(x => {
                            return page.host.filehost + x
                        })
                        data.XQT = XQT
                        page.itemObj = data

                        page.$nextTick(function () {
                            uParse('.contentA', {
                                rootPath: '/static/libs/ueditor/'
                            })
                        });

                    } else {
	                    Toast({
	                        message: res.msg,
	                        duration: 2000
	                    });
	                    setTimeout(function () {
	                    	page.$router.go(-1);
	                    },2000);
                    }

                }
            }

        },
        mounted() {
            // console.log(this.$route.params);
            // var data = this.$route.params;
            // if (data) {
            // 	var id = data.id;
            // } else {
            // 	console.log('无路由ID')
            // }
            let id = this.$route.params.id
            this.pdid = id
            this.getGiftDetailFn(id);
        }
    }

</script>

<style lang="less">
    .insetbox2 {
        display: flex;
        justify-content: center;
        padding-top: 0.15rem;
        /*background-color: #e9e9e9;*/
    }

    .rapdetail {
        background-color: #fff;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 0.64rem;
        box-shadow: 0 0 0.05rem #aaa;
        .ph {
            img {
                width: 5.82rem;
                height: 3.7rem;
                border-radius: 0.15rem;
            }
        }
        .name {
            margin: 0.4rem 0;
            width: 5.9rem;
            border-top: 0.04rem solid #e2e2e2;
            border-bottom: 0.04rem solid #e2e2e2;
            padding: 0.03rem 0;
            .inbox {
                width: 5.9rem;
                height: 0.66rem;
                background-color: #e2e2e2;
                text-align: center;
                line-height: 0.66rem;
                color: #F05DC4;
                font-size: 0.36rem;
            }
        }
        .msph {
            width: 5.9rem;
            height: 2.35rem;
            border-bottom: 0.03rem solid #e2e2e2;
            img {
                width: 6.18rem;
                height: 2.35rem;
                margin-left: -0.25rem;
            }
        }
        .btn {
            margin-top: 0.46rem;
            width: 2.6rem;
            height: 0.88rem;
            border-radius: 0.12rem;
            line-height: 0.88rem;
            text-align: center;
            color: #fff;
            font-size: 0.39rem;
            background-color: #F05DC4;
        }
    }

    // newweigang
    .rapcontant {
        .topimg {
            height: 4rem;
            img {
                width: 100%;
                height: 100%;
            }
        }
        .title {
            font-weight: bold;
            font-size: .36rem;
            padding: .2rem .2rem .1rem .2rem;
        }
        .detailsm {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 8px solid #f4f4f4;
            .jg {
                color: #F05DC4;
                font-size: .42rem;
                font-weight: bold;
                padding: .2rem .2rem .2rem .2rem;
                span {
                    font-size: .28rem;
                    color: #666666;
                    text-decoration: line-through;
                }
            }
            .jf {
                padding-right: .2rem;
                font-size: .28rem;
                color: #666666;
                span {
                    color: #F05DC4;
                }
            }

        }
        .zsjf {
            border-bottom: 1px solid #f4f4f4;
            padding: .2rem .2rem .2rem .2rem;
            color: #F05DC4;
            font-size: .30rem;
            span {
                color: #F05DC4;
                font-size: .30rem;
            }
        }
        .spjssm {
            border-bottom: 8px solid #f4f4f4;
            padding: .1rem .2rem .3rem .2rem;
            color: #666666;
        }
        .xqxz {
            padding: 10px;
        }
    }

    .footbuy {
        position: fixed;
        bottom: 0;
        width: 100%;
        text-align: center;
        background-color: #F05DC4;
        color: #fff;
        height: 48px;
        line-height: 48px;
        font-size: 18px;
    }
</style>
